/*实力评级----team detail*/

EMui.vmRatingTeamDetail=(function(){
    var id=EMui.utils.getUrlParam("id");


    //添加 swiper 滑动功能；
    var addSwiper=function (view) {
        $('.p-btns').removeClass('hide');
        new Swiper('.swiper-container', {
            pagination: '.swiper-pagination',
            slidesPerView: 5,
            prevButton:'.swiper-button-prev',
            nextButton:'.swiper-button-next'
        });
        view.state.isAddSlider = true;
    };


    //图表参数配置
    var lineOpt ={
        tooltip : {show:false},
        grid: {left: '12%',top:'10%', right: '6%', bottom: '14%', containLabel: false},
        xAxis : [
            {
                type : 'category',
                axisLine: { lineStyle: { color: '#1b4361', width: 2 },onZero: false },
                splitLine: {
                    lineStyle: { color: '#225981' },
                    interval:function(index,value){
                        if(index<8){
                            return true;
                        }else{
                            return false;
                        }
                    }
                },
                axisTick: { show: false },
                axisLabel : {
                    formatter:  function(value,idx){return '0'+(++idx)},
                    textStyle: { color: '#ffffff' }
                },
                data:function () {
                    var list = [];
                    for (var i = 1; i <= 8; i++) {
                        var str = '0'+i;
                        list.push(str);
                    }
                    return list;
                }()
            }
        ],
        yAxis : [
            {
                type : 'value',
                axisLine : {lineStyle: { color: '#1b4361', width: 2 }},
                splitLine: {  lineStyle: { color: '#02807c', type: 'dotted' }}, //dotted,dashed
                axisTick: { show: false },
                axisLabel: {
                    formatter: function (value) {
                        if (value > 10000) {
                            return parseInt(value / 1000) + " k ";
                        } else {
                            return value;
                        }

                    },
                    textStyle: { color: '#ffffff' }
                },

                scale:true

            }
        ],
        series : [
            {
                type:'line',
                smooth:true,
                itemStyle: {  normal: {color: '#ffffff',borderWidth:4}},
                lineStyle : {  normal: { color: '#7ed2f5'}},
                data:[]
            }
        ]
    };

    //get data
    function getData(li) {
        var data = $.trim(li.attr("data-integral")), numArr = [];
        if (data) {
            data = data.split(",");
            $.each(data, function (index, item) {
                numArr.push(item * 1);
            });
        }
        return numArr;
    }


    function showChat(chat,curLi,opts) {
        opts.series[0].data = getData(curLi);
        chat.setOption(opts);
    }


    var view= new LeafView({
        id:"#ratingTeamDetail",
        state:{isAddSlider:false,isShow:true},
        param:{
            url:EMui.urls.domain+EMui.urls.ratingTeamDetail+"/"+id,
            data:{id:0}
        },
        vm:new Vue({
            el:$("#ratingTeamDetail")[0] ,
            data:{list:[],detail:null},
            watch:{
                'detail':function (val,oldVal) {
                    var me=view;

                    //队员列表，滑动功能；
                    if(val.PlayerList && val.PlayerList.length && val.PlayerList.length>5){
                        if (!me.state.isAddSlider) {
                            addSwiper(me)
                        }
                    }

                    //图表功能
                    if(val.StrengthList && val.StrengthList.length && val.StrengthList.length>0){

                        var chartZone=$("#chartZone");
                        var tab=$(".p-tab-h",chartZone);
                        var lis=$("li",tab);

                        //first load
                        var curLi =lis.filter(".cur");
                        var pChart = echarts.init(document.getElementById('lineBox')),
                            pOpts = $.extend(true, {}, lineOpt);
                        showChat(pChart, curLi, pOpts);


                        //tabs switch
                        lis.on("changetab", function () {
                            curLi = $(this);
                            showChat(pChart, curLi, pOpts);
                        });
                    }

                }
            }
        }),
        isLoadMore:false
    });

    return{
        init:function(){
            view.param.data.id=id;
            view.fillData();
        },
        reloadData:function(){
            view.vm.list=[];
            view.fillData();
        }
    }
})();



